
# -*- coding: utf-8 -*-

# __date:   2021/7/4 
# __author: Yang Chao
# __function:

class Solution:

    def romanToInt(self, s: str) -> int:
        temp = {
            "I": 1,
            "V": 5,
            "X": 10,
            "L": 50,
            "C": 100,
            "D": 500,
            "M": 1000
        }
        total = 0
        for i in range(len(s) - 1):
            if temp[s[i]] < temp[s[i + 1]]:
                total -= temp[s[i]]
            else:
                total += temp[s[i]]
        total += temp[s[-1]]
        return total
